package club.janna.netty.limiter;

import com.google.common.util.concurrent.RateLimiter;
import lombok.extern.slf4j.Slf4j;

import java.util.Random;

/**
 * 限流器
 */
@Slf4j
public class LimiterDemo {
    public static void main(String[] args) throws InterruptedException {
        RateLimiter limiter = RateLimiter.create(5);
        Random random = new Random();
        for (int i = 0; i < 100; i++) {
            Thread.sleep(random.nextInt(200));
            if(limiter.tryAcquire())
                log.info(i + " 执行了");
        }
    }
}
